﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using STHPMS1.ICore.I_Entity.Stmpms1;
namespace STHPMS1.Common.C_Utils
{
    public class Calc
    {
        #region SSI
        /// <summary>
       /// SSI
       /// </summary>
       /// <param name="ld">路面设计弯沉</param>
       /// <param name="lo">实测代表弯沉</param>
       /// <returns></returns>
        public static double SSI(double ld,double lo)
        {
            return ld/lo;
        }
        #endregion 

        #region 公路技术状况指数
        /// <summary>
        /// 公路技术状况指数MQI
        /// </summary>
        /// <returns></returns>
        public static double MQI(double PQI, double SCI, double BCI, double TCI)
        {
            return (0.7*PQI+0.08*SCI+0.12*BCI+0.1*TCI);
        }
        #endregion

        #region 路面使用性能PQI(高速公路，一级公路)
        /// <summary>
        /// 路面使用性能PQI(高速公路，一级公路)
        /// </summary>
        /// <returns></returns>
        public static double PQI(double PCI, double RQI, double RDI, double SRI)
        {
            return 0.35*PCI+0.4*RQI+0.15*RDI+0.1*SRI;
        }
        #endregion

        #region 路面使用性能PQI（二，三，四级公路）
        /// <summary>
        /// 路面使用性能PQI（二，三，四级公路）
        /// </summary>
        /// <returns></returns>
        public static double PQI(double PCI, double RQI)
        {
            return 0.6*PCI+0.4*RQI;
        }
        #endregion

        #region 路面病害-沥青路面
        /// <summary>
        /// 路面病害-沥青路面
        /// </summary>
        /// <param name="info"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static double PCI(IS_Pmds_Asp info, double length)
        {
            return Convert.ToDouble(100 - (15 * Math.Pow(DR(info, length), 0.412)));
        }
        #endregion 

        #region 路面病害-DR
        /// <summary>
        /// 路面病害-DR
        /// </summary>
        /// <param name="info"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static double DR(IS_Pmds_Asp info, double length)
        {
            double Algck=Convert.ToDouble(0.6*info.Algck_L+0.8*info.Algck_M+1*info.Algck_H);
            double BLFT = Convert.ToDouble(0.6 * info.Blft_L + 0.8 * info.Blft_H);
            double LGCK = Convert.ToDouble(0.6 * info.Lgck_L + 1 * info.Lgck_H);
            double TRSCK = Convert.ToDouble(0.6 * info.Trsck_L + 1 * info.Trsck_H);
            double PIT = Convert.ToDouble(0.8 * info.Pit_L + 1 * info.Pit_H);
            double LOS = Convert.ToDouble(0.6 * info.Los_L + 1 * info.Los_H);
            double SINK = Convert.ToDouble(0.6 * info.Sink_L + 1 * info.Sink_H);
            double PLWV = Convert.ToDouble(0.6 * info.Plwv_L + 1 * info.Plwv_H);
            double RUT = Convert.ToDouble(0.6 * info.Rut_L + 1 * info.Rut_H);
            double BLED = Convert.ToDouble(0.2 * info.Bled);
            double REPAIR = Convert.ToDouble(0.1 * info.Repair);
            double dr = Convert.ToDouble((Algck + BLFT + LGCK + TRSCK + PIT + LOS + SINK + PLWV + RUT + BLED + REPAIR) / (length * info.Pmwid));
            return dr;

        }
        #endregion 

        #region 路面平整度(高速公路和一级公路)
        /// <summary>
        /// 路面平整度(高速公路和一级公路)
        /// </summary>
        /// <returns></returns>
        public static double RQI1(IS_Rdrgh info)
        {
            
            double a1iri = Convert.ToDouble(0.65 * info.Iri);
            double aoe = 0.026 * Math.Pow(2.718, a1iri);
            return Convert.ToDouble(100/(1+aoe));
        }
        #endregion

        #region 路面平整度(二，三，四级公路)
        /// <summary>
        /// 路面平整度(二，三，四级公路)
        /// </summary>
        /// <returns></returns>
        public static double RQI2(IS_Rdrgh info)
        {
            
            double a1iri = Convert.ToDouble(0.58 * info.Iri);
            double aoe = 0.0185 * Math.Pow(2.718, a1iri); ;
            return Convert.ToDouble(100 / (1 + aoe));
        }
        #endregion 

        #region 路面车辙RDI
        /// <summary>
        /// 路面车辙RDI
        /// </summary>
        /// <returns></returns>
        public static double RDI(double RD)
        {
            double returnvalue = 0;
            if (RD <= 20)
            {
                returnvalue = 100 - 2 * RD;
            }
            if (RD > 20 && RD <= 35)
            {
                returnvalue = 60 - 4*(RD - 20);
            }
            if (RD > 35)
            {
                returnvalue = 0;
            }
            return returnvalue;
        }
        #endregion

        #region 路面结构强度PSSI
        /// <summary>
        /// 路面结构强度PSSI
        /// </summary>
        /// <returns></returns>
        public static double PSSI(double ssi)
        {
            double a1ssi = -5.19 * ssi;
            double aoe = 15.71 * Math.Pow(2.718,a1ssi);
            return 100/(1+aoe);
        }
        #endregion 

        #region 路面抗滑 SRI
        /// <summary>
        /// 路面抗滑 SRI
        /// </summary>
        /// <returns>横向力系数</returns>
        public static double SRI(double sfc)
        {
            double a1sfc = -0.105 * sfc;
            double aoe =28.6*Math.Pow(2.718, a1sfc);
            return (100 - 35) / (1 + aoe) + 35;
        }
        #endregion 

        #region 路基技术状况SCI
        /// <summary>
        /// 路基技术状况SCI
        /// </summary>
        /// <returns></returns>
        public static double SCI(IS_Subgrd info)
        {
            //1
            double SLDDHIM = 100-(Convert.ToDouble(info.Slddhim * 0.5) > 100 ? 100 : Convert.ToDouble(info.Slddhim * 0.5));
            //2
            double SLDDG_L = Convert.ToDouble(info.Slddg_L * 1);
            double SLDDG_H = Convert.ToDouble(info.Slddg_H * 2);
            double SLDDG =100-((SLDDG_L + SLDDG_H) > 100 ? 100 : (SLDDG_L + SLDDG_H));
            //3
            double SLPCP_L = Convert.ToDouble(info.Slpcp_L * 20);
            double SLPCP_M = Convert.ToDouble(info.Slpcp_M * 30);
            double SLPCP_H = Convert.ToDouble(info.Slpcp_H * 50);
            double SLPCP = 100-((SLPCP_L + SLPCP_M + SLPCP_H) > 100 ? 100 : (SLPCP_L + SLPCP_M + SLPCP_H));
            //4
            double WATGUY_L = Convert.ToDouble(info.Watguy_L * 20);
            double WATGUY_M = Convert.ToDouble(info.Watguy_M * 30);
            double WATGUY_H = Convert.ToDouble(info.Watguy_H * 50);
            double WATGUY = 100-((WATGUY_L + WATGUY_M + WATGUY_H) > 100 ? 100 : (WATGUY_L + WATGUY_M + WATGUY_H));

            //5
            double DASUGCT_L = Convert.ToDouble(info.Dasugct_L * 20);
            double DASUGCT_M = Convert.ToDouble(info.Dasugct_M * 30);
            double DASUGCT_H = Convert.ToDouble(info.Dasugct_H * 50);
            double DASUGCT = 100-((DASUGCT_L + DASUGCT_M + DASUGCT_H) > 100 ? 100 : (DASUGCT_L + DASUGCT_M + DASUGCT_H));

            //6
            double CUBDAMG =100-(Convert.ToDouble(info.Cubdamg * 4) > 100 ? 100 : Convert.ToDouble(info.Cubdamg * 4));
            //7
            double SUBSLT_L = Convert.ToDouble(info.Subslt_L * 20);
            double SUBSLT_M = Convert.ToDouble(info.Subslt_M * 30);
            double SUBSLT_H = Convert.ToDouble(info.Subslt_H * 50);
            double SUBSLT = 100-((SUBSLT_L + SUBSLT_M + SUBSLT_H) > 100 ? 100 : (SUBSLT_L + SUBSLT_M + SUBSLT_H));
            //8
            double DRSYST_L = Convert.ToDouble(info.Drsyst_L * 1) > 100 ? 100 : Convert.ToDouble(info.Drsyst_L * 1);
            double DRSYST_H = Convert.ToDouble(info.Drsyst_H * 20) > 100 ? 100 : Convert.ToDouble(info.Drsyst_H * 20);
            double DRSYST = 100-((DRSYST_L + DRSYST_H) > 100 ? 100 : (DRSYST_L + DRSYST_H));

            return (0.05 * SLDDHIM) + SLDDG * 0.10 + SLPCP * 0.25 + WATGUY * 0.25
                + DASUGCT * 0.10 + CUBDAMG * 0.05 + SUBSLT * 0.10 + DRSYST*0.10;
        }
        #endregion 

        #region 桥隧构造物 BCI
        /// <summary>
        /// 桥隧构造物 BCI
        /// </summary>
        /// <returns></returns>
        public static double BCI(IS_Btstrut info)
        {
            double t;
            double min;
            double BDTC_OT = Convert.ToDouble(info.Bdtc_Ot * 0);
            double BDTC_THR = Convert.ToDouble(info.Bdtc_Thr * 40);
            double BDTC_FU = Convert.ToDouble(info.Bdtc_Fu * 70);
            double BDTC_FV = Convert.ToDouble(info.Bdtc_Fv * 100);

            double BDTC = 100-((BDTC_OT + BDTC_THR + BDTC_FU + BDTC_FV) > 100 ? 100 : (BDTC_OT + BDTC_THR + BDTC_FU + BDTC_FV));

            double TUNL_N = Convert.ToDouble(info.Tunl_N * 0);
            double TUNL_A = Convert.ToDouble(info.Tunl_A * 50);
            double TUNL_D = Convert.ToDouble(info.Tunl_D * 100);

            double TUNL = 100-((TUNL_N + TUNL_A + TUNL_D) > 100 ? 100 : (TUNL_N + TUNL_A + TUNL_D));

            double CLVT_F = Convert.ToDouble(info.Clvt_F * 0);
            double CLVT_LP = Convert.ToDouble(info.Clvt_Lp * 40);
            double CLVT_P = Convert.ToDouble(info.Clvt_P * 70);
            double CLVT_D = Convert.ToDouble(info.Clvt_D * 100);

            double CLVT =100- ((CLVT_F + CLVT_LP + CLVT_P + CLVT_D) > 100 ? 100 : (CLVT_F + CLVT_LP + CLVT_P + CLVT_D));

            if (BDTC > TUNL)
            {
                t = TUNL;
            }
            else { t = BDTC; }

            if(t>CLVT)
            {
                min = CLVT;
            }
            else { min = t; }

            return min;
        }
        #endregion 

        #region 沿线设施 TCI
        /// <summary>
        /// 沿线设施 TCI
        /// </summary>
        /// <returns></returns>
        public static double TCI(IS_Rddf info)
        {
            double PTFLDF_L =Convert.ToDouble(info.Ptfldf_L * 10);
            double PTFLDF_H = Convert.ToDouble(info.Ptfldf_H * 30);
            double PTFLDF = 100-((PTFLDF_L + PTFLDF_H) > 100 ? 100 : (PTFLDF_L + PTFLDF_H));

            double ISGTDMG = 100-(Convert.ToDouble(info.Isgtdmg * 20) > 100 ? 100 : Convert.ToDouble(info.Isgtdmg * 20));
            double MKDEFT = 100- (Convert.ToDouble(info.Mkdeft * 20) > 100 ? 100 : Convert.ToDouble(info.Mkdeft * 20));
            double INDEFT = 100-(Convert.ToDouble(info.Indeft * 0.1) > 100 ? 100 : Convert.ToDouble(info.Indeft * 0.1));
            double AFMNGPR = 100-(Convert.ToDouble(info.Afmngpr * 0.1) > 100 ? 100 : Convert.ToDouble(info.Afmngpr * 0.1));

            return 0.25 * PTFLDF + 0.1 * ISGTDMG + 0.25 * MKDEFT + 0.2 * INDEFT + 0.20 * AFMNGPR;
        }
        #endregion 
    }
}
